package com.test.demo.controller;

import com.test.demo.pojo.Account;
import com.test.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping(value = "/list")
    public List<Account> getAccountList(){
        return accountService.findAccountList();
    }

    @RequestMapping(value = "/{id}")
    public Account getAccount(@PathVariable("id") int id){
        return accountService.findAccount(id);
    }

    @RequestMapping(value = "/{name}/{money}")
    public String addAccount(@PathVariable("name")String name,@PathVariable("money")double money){
        int i=accountService.add(name,money);
        if(i>0){
            return "success";
        }else {
            return "fail";
        }
    }
}
